﻿using System;
using System.Collections.Generic;

namespace GeneticAlgorithm
{
    public class Generator
    {
        public const int MaxPrice = 5000;
        public const int MaxRelevation = 10;
        public const int MaxMargin = 5000;
        public const int MaxCount = 100;
        public const int CategoryCount = 10;
        public const int ItemCount = 1000;
        public const int NameMaxLength = 10;

        public static List<Item> GenerateFirstPopulation()
        {
            var random = new Random();
            var list = new List<Item>();
            
            for (var item = 0; item < ItemCount; item++)
            {
                var newItem = new Item();
                newItem.Price = random.Next(MaxPrice) + 1;
                newItem.Margin = random.Next(newItem.Price) + 1;
                newItem.Count = random.Next(MaxCount) + 1;
                newItem.Category = random.Next(CategoryCount);

                newItem.Name = GenerateName(random);
                list.Add(newItem);
            }
            return list;
        }

        public static string GenerateName()
        {
            return GenerateName(new Random());
        }

        public static string GenerateName(Random random)
        {
            var length = random.Next(NameMaxLength)+1;
            var name = "";
            for (var letter = 0; letter < length; letter++)
            {
                var ch = (char) ('а' + random.Next(32));
                name += ch;
            }
            return name;
        }

        public static List<int> GenerateRelevance()
        {
            var res = new List<int>();
            var random = new Random();
            for (int i = 0; i < CategoryCount; i++)
            {
                res.Add(random.Next(MaxRelevation));
            }
            return res;
        }
    }
}